home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / +system+ / tools / sound / ahi / developer / devloper.lzx / examples / Low-level / BestAudioID / BestAudioID.c < prev    next >
C/C++ Source or Header  |  1980-02-21  |  3KB  |  109 lines

  1. /* Simple AHI_BestAudioID() example */
  2.  
  3. #include <devices/ahi.h>
  4. #include <proto/exec.h>
  5. #include <proto/dos.h>
  6. #include <proto/ahi.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. struct Library    *AHIBase;
  11. struct MsgPort    *AHImp=NULL;
  12. struct AHIRequest *AHIio=NULL;
  13. BYTE               AHIDevice=-1;
  14.  
  15. void cleanup(LONG rc)
  16. {
  17.   if(!AHIDevice)
  18.     CloseDevice((struct IORequest *)AHIio);
  19.   DeleteIORequest((struct IORequest *)AHIio);
  20.   DeleteMsgPort(AHImp);
  21.   exit(rc);
  22. }
  23.  
  24. void printmode(ULONG id) {
  25.   char name[40];
  26.  
  27.   if(id != AHI_INVALID_ID) {
  28.     name[0] = '\0';
  29.     AHI_GetAudioAttrs(id, NULL,
  30.         AHIDB_BufferLen, 40,
  31.         AHIDB_Name, (ULONG) name,
  32.         TAG_DONE);
  33.   }
  34.   else {
  35.     strncpy(name, "Non-existing mode!", 40);
  36.   }
  37.  
  38.   Printf("\nMode 0x%08lx (%s):\n",  id, name);
  39. }
  40.  
  41.  
  42. void main(void)
  43. {
  44.   ULONG mainid, id;
  45.  
  46.   if(AHImp=CreateMsgPort())
  47.     if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) {
  48.       AHIio->ahir_Version = 4;
  49.       AHIDevice=OpenDevice(AHINAME,AHI_NO_UNIT,(struct IORequest *)AHIio,NULL);
  50.       }
  51.  
  52.   if(AHIDevice) {
  53.     Printf("Unable to open %s version 4\n",AHINAME);
  54.     cleanup(RETURN_FAIL);
  55.   }
  56.   AHIBase=(struct Library *)AHIio->ahir_Std.io_Device;
  57.  
  58.   mainid = AHI_BestAudioID(AHIDB_Stereo,TRUE,
  59.                      AHIDB_Volume,TRUE,
  60.                      AHIDB_Bits,8,
  61.                      AHIDB_MaxChannels,4,
  62.                      TAG_DONE);
  63.   printmode(mainid);
  64.   Printf("Stereo, Volume, >= 8 bits and >= 4 channels.\n");
  65.  
  66.   {
  67.     struct TagItem tags[] = {
  68.       AHIDB_Bits, 12,
  69.       AHIDB_Panning, TRUE,
  70.       AHIDB_HiFi, TRUE,
  71.       TAG_DONE
  72.     };
  73.     id = AHI_BestAudioID(AHIDB_Stereo,TRUE,
  74.                        AHIDB_Volume,TRUE,
  75.                        AHIDB_Bits,8,
  76.                        AHIDB_MaxChannels,4,
  77.                        AHIB_Dizzy, (ULONG) &tags,
  78.                        TAG_DONE);
  79.     printmode(id);
  80.     Printf("Same as 0x%08lx but also, if possible, "
  81.            ">= 12 bits, free stereo panning and HiFi mixing.\n", mainid);
  82.   }
  83.  
  84.   {
  85.     struct TagItem tags[] = {
  86.       AHIDB_Bits, 16,
  87.       AHIDB_Stereo, FALSE,
  88.       TAG_DONE
  89.     };
  90.  
  91.     id = AHI_BestAudioID(AHIDB_AudioID,id,
  92.                        AHIB_Dizzy, (ULONG) &tags,
  93.                        TAG_DONE);
  94.  
  95.     printmode(id);
  96.     Printf("Using the same audio hardware at last mode, "
  97.            "this modes may have >= 16 bit resolution and be mono. But "
  98.            "I'm not sure.\n");
  99.   }
  100.  
  101.   id = AHI_BestAudioID(AHIDB_Realtime, FALSE,
  102.                      AHIDB_MaxChannels, 4,
  103.                     TAG_DONE);
  104.   printmode(id);
  105.   Printf("A non-realtime mode with 4 channels.\n");
  106.  
  107.   cleanup(0);
  108. }
  109.